package lv.accenture.ex07;

public class TestRunner {

	public static void main(String[] args) {
		HelloRunner r = new HelloRunner();
		Thread t1 = new Thread(r, "R1");
		Thread t2 = new Thread(r, "R2");
		Thread t3 = new Thread(r, "R3");
		t1.start();
		t2.start();
		t3.start();
	}
}

class HelloRunner implements Runnable {
	private int j=0;
	public void run() {
		/*for (int i = 0; i < 50; i++) {
			System.out.println("Hello #" + j + " from "
					+ Thread.currentThread().getName());
			j++;
		
		}*/
		
		{
		while (j<1500)
		{
			System.out.println("Hello #" + j + " from "
					+ Thread.currentThread().getName());
			synchronized (this) {
				j++;

			}
			try
			{
			  Thread.sleep(1);
			}
			catch (InterruptedException e)
			{
				System.err.println("Interrupted");
			}
			
		}
		}
	}
}
